﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace JuCloudy.Platform.Structure.UI.Module
{
    public partial class UpdataDiary : UserControl
    {
        public UpdataDiary()
        {
            InitializeComponent();
        }

        public UpdataDiary(String content)
        {
            items.Add(GetContent(content));

            this.Loaded += (obj, e) =>
            {
                this.OnLoad();
            };
        }

        public UpdataDiary(IList<JuCloudy.Framework.Data.UpdateDiaryEntity> entities)
        {
            foreach (var m in entities)
            {
                items.Add(GetTitle("·"+m.Title));
                for (int i = 0; i < m.Contents.Count; i++)
                {
                    items.Add(GetContent((i + 1).ToString() + "." + m.Contents[i]));
                }
            }


            this.Loaded += (obj, e) =>
            {
                this.OnLoad();
            };
        }

        public List<TextBlock> items
        {
            get;
            set;
        }

        private TextBlock GetTitle(String content)
        {
            return new TextBlock() 
            { FontSize = 16, 
                Text = content,
                Padding = new Thickness(0,5,0,5)
            };
        }

        private TextBlock GetContent(string content)
        {
            return new TextBlock()
            {
                FontSize = 13,
                Text = content,
                Padding = new Thickness(15, 5, 0, 5)
            };
        }

        private void OnLoad()
        {
            foreach (var item in items)
            {
                this.MainRoot.Children.Add(item);
            }
        }
    }
}
